<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" template="/home.xhtml">
	
	<ui:define name="corpo">
		
			<p:panel header="Área do Paciente" style="background: #dbfbda;font-size:15px;min-height:700px;margin-top:10px;float:left;width:99%">
				<h:panelGroup style="float: left;width:250px;" layout="block">
					<h:form prependId="false">
						<ui:include src="menu_esquerda.xhtml" />
					</h:form>	
				</h:panelGroup>
				
				<h:panelGroup layout="block" style="float:left">					
					<p:panel header="Informações pessoais" style="width:700px;float:left">
						<h:form prependId="false" id="formPrincipal">
							<h:panelGroup layout="block">							
									<p:fieldset legend="Dados Pessoais" toggleable="true" style="float:left;width:645px;font-size:13px">
										<h:panelGrid columns="4" cellpadding="1" cellspacing="2" id="pnl1">
										
											<h:outputLabel value="#{msg['display.label.paciente.nome']}" for="nome" styleClass="fmt_label_form_cadastro" />
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.nome}" size="40" maxlength="100" required="true" label="nome" id="nome" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											<h:outputText />
											<h:outputText />											
											
											<h:outputText />
											<h:message for="nome" id="msgNome" style="margin-left:5px" styleClass="msg_erro_required"/>
											<h:outputText />
											<h:outputText />	
												
											<h:outputLabel value="#{msg['display.label.paciente.cpf']}" for="cpf" styleClass="fmt_label_form_cadastro" />									
											<p:inputMask value="#{marcacaoConsultaPacienteBean.form.paciente.cpf}" mask="999.999.999-99" size="14" maxlength="14" required="true" label="cpf" id="cpf" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
												<f:converter converterId="com.automed.cpfConverter"/>
												<f:validator validatorId="com.automed.cpfValidator"/>
											</p:inputMask>																					
											<h:outputLabel value="#{msg['display.label.paciente.rg']}" for="rg" styleClass="fmt_label_form_cadastro" />											
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.rg}" size="12" maxlength="12" required="true" label="rg" id="rg" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											
											<h:outputText />
											<h:message for="cpf" id="msgCPF" style="margin-left:5px" styleClass="msg_erro_required"/>
											<h:outputText />
											<h:message for="rg" id="msgRG" style="margin-left:5px" styleClass="msg_erro_required"/>										
												
											<h:outputLabel value="#{msg['display.label.paciente.login']}" for="login" styleClass="fmt_label_form_cadastro" />
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.login}" size="10" maxlength="50" required="true" label="login" id="login" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											<h:outputLabel value="#{msg['display.label.paciente.senha']}" for="senha" styleClass="fmt_label_form_cadastro" />
											<p:commandLink onclick="editPassword.show();" update="gridCad">Alterar senha</p:commandLink>
												
											<h:outputText />
											<h:message for="login" id="msgLogin" style="margin-left:5px" styleClass="msg_erro_required"/>	
											<h:outputText />
											<h:outputText />
											
											<h:outputLabel value="#{msg['display.label.paciente.matricula']}" for="matricula" styleClass="fmt_label_form_cadastro" />
											<p:inputMask value="#{marcacaoConsultaPacienteBean.form.paciente.matricula}" mask="9999999999" size="10" maxlength="10" required="true" label="matricula" id="matricula" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
												<p:tooltip for="matricula" value="Por favor, digite a matrícula fornecida pelo seu convênio" showEvent="focus" hideEvent="blur"/>
											</p:inputMask>
											<h:outputLabel value="#{msg['display.label.paciente.convenio']}" for="convenio" styleClass="fmt_label_form_cadastro" />
											<h:panelGroup>
												<h:selectOneMenu value="#{marcacaoConsultaPacienteBean.form.paciente.convenio}" id="convenio" required="true" style="font-size:12px;">
													<f:selectItem itemLabel="" noSelectionOption="true" />
													<f:selectItems value="#{manterPacienteBean.pacienteForm.convenios}" var="entity" itemLabel="#{entity.convenio}" itemValue="#{entity}" />
												</h:selectOneMenu>	
											</h:panelGroup>
											
											<h:outputText />
											<h:message for="matricula" style="margin-left:5px" id="msgMatricula" styleClass="msg_erro_required"/>
											<h:outputText />
											<h:message for="convenio" style="margin-left:5px" id="msgConvenio" styleClass="msg_erro_required" />
											
										</h:panelGrid>
									</p:fieldset>
									
									<p:fieldset legend="Contato" id="pnlContato" toggleable="true" style="margin-top:20px;float:left;width:645px;font-size:13px">
									
										<h:panelGroup layout="block" style="float:left;width:70px;margin-top:5px">
											<h:outputLabel value="#{msg['display.label.paciente.email']} " for="email" styleClass="fmt_label_form_cadastro" />
										</h:panelGroup>
										<h:panelGroup layout="block" style="float:left;width:520px;">
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.email}" size="40" maxlength="50" required="true" label="email" id="email" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
												<f:validator validatorId="com.automed.emailValidator"/>
											</p:inputText>
											<h:message for="email" id="msgEmail" styleClass="msg_erro_required"/>
										</h:panelGroup>	
												
											
										<ui:repeat var="entity" value="#{marcacaoConsultaPacienteBean.form.paciente.telefones}">
											<br /><br />
											<h:panelGroup layout="block" style="float:left;width:70px;margin-top:5px">
												<h:outputLabel value="#{entity.tipoTelefone.tipo eq 'Celular' ? 'Celular: ' : (entity.tipoTelefone.tipo eq 'Comercial' ? 'Comercial: ' : (entity.tipoTelefone.tipo eq 'Residencial' ? 'Residencial: ' : ''))}" for="tel1" styleClass="fmt_label_form_cadastro" />
											</h:panelGroup>
												
											<h:panelGroup layout="block" style="float:left;width:520px;">
												<p:inputMask value="#{entity.telefone}" mask="(99)9999-9999" converter="com.automed.marcaraFoneConverter"  required="true" id="tel1" size="13" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
												<h:message for="tel1" style="margin-left:5px" id="msgTEL1" styleClass="msg_erro_required"/>
											</h:panelGroup>
			
										</ui:repeat>
									
									</p:fieldset>
									
									<p:fieldset legend="Endereço" toggleable="true" style="margin-top:20px;float:left;width:645px;font-size:13px">
										<h:panelGrid columns="4" cellpadding="2" border="0" cellspacing="1" id="pnl2" width="600">
												
											<h:outputLabel value="#{msg['display.label.paciente.logradouro']}" for="logradouro" styleClass="fmt_label_form_cadastro" />
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.endereco.endereco}" required="true" size="40" maxlength="100" label="logradouro" id="logradouro" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											<h:outputLabel value="#{msg['display.label.paciente.numero']}" for="numero" styleClass="fmt_label_form_cadastro" />
											<p:inputMask value="#{marcacaoConsultaPacienteBean.form.paciente.endereco.numero}" required="true" mask="?999999" size="6" label="numero" id="numero" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											
											
											<h:outputText />
											<h:message for="logradouro" id="msgLogradouro" styleClass="msg_erro_required"/>
											<h:outputText />
											<h:message for="numero" id="msgNumero" styleClass="msg_erro_required" />
											
											<h:outputLabel value="#{msg['display.label.paciente.complemento']}" for="complemento" styleClass="fmt_label_form_cadastro" />
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.endereco.complemento}" required="false" size="10" maxlength="50" label="complemento" id="complemento" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											<h:outputLabel value="#{msg['display.label.paciente.cidade']}" for="cidade" styleClass="fmt_label_form_cadastro" />
											<h:panelGroup>
												<h:selectOneMenu value="#{marcacaoConsultaPacienteBean.form.paciente.endereco.cidade}" required="true" id="cidade" style="font-size:12px;width:140px">
													<f:selectItem itemLabel="" noSelectionOption="true" />
													<f:selectItems value="#{manterPacienteBean.pacienteForm.cidades}" var="entity" itemLabel="#{entity.cidade}" itemValue="#{entity}" />
												</h:selectOneMenu>
											</h:panelGroup>
											
											<h:outputText />
											<h:message for="complemento" id="msgComplemento" styleClass="msg_erro_required"/>
											<h:outputText />
											<h:message for="cidade" id="msgCidade" styleClass="msg_erro_required"/>
											
											
											<h:outputLabel value="#{msg['display.label.paciente.bairro']}" for="bairro" styleClass="fmt_label_form_cadastro" />
											<p:inputText value="#{marcacaoConsultaPacienteBean.form.paciente.endereco.bairro}" required="true" size="30" maxlength="100" label="bairro" id="bairro" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											<h:outputLabel value="#{msg['display.label.paciente.cep']}" for="cep" styleClass="fmt_label_form_cadastro" />
											<p:inputMask value="#{marcacaoConsultaPacienteBean.form.paciente.endereco.cep}" mask="99999-999" size="9" maxlength="8" required="true" label="cep" id="cep" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
											
											<h:outputText />
											<h:message for="bairro" id="msgBairro" styleClass="msg_erro_required"/>
											<h:outputText />
											<h:message for="cep" id="msgCEP" styleClass="msg_erro_required"/>			
												
										</h:panelGrid>
									</p:fieldset>
									
									<h:panelGroup style="text-align:center;" layout="block">
										<p:commandButton value="Salvar alterações" style="margin-top:10px" update="formModal,call_func,msgNome,msgCPF,msgRG,msgLogin,msgMatricula,msgConvenio,pnlContato,msgLogradouro,msgNumero,msgComplemento,msgCidade,msgBairro,msgCEP" oncomplete="call_modalInformacao();" action="#{marcacaoConsultaPacienteBean.atualizarDadosPaciente}" />
									</h:panelGroup>
								
							</h:panelGroup>
						</h:form>
					</p:panel>
				</h:panelGroup>
			</p:panel>
			
			<h:panelGroup id="call_func">
				<script type="text/javascript">
					function call_modalInformacao(){
						if(#{requestScope.status eq 'sucess'}){
							confirmacaoAlteracao.show();
						}
					}
				</script>
			</h:panelGroup>
			
			
			<p:dialog header="Aviso" widgetVar="confirmacaoAlteracao" resizable="false" modal="true" width="320" showEffect="clip" hideEffect="fold">
				<h:form prependId="false" id="formModal">
					<h:panelGroup layout="block" style="text-align:center">
						<h:outputText styleClass="#{requestScope.status eq 'sucess' ? 'sucesso_consulta' : 'erro_consulta'}" value="#{requestScope.status eq 'sucess' ? 'Alteração feita com sucesso' : (requestScope.status eq 'error' ? 'Erro, entre em contato com o administrador' : '')}" />
						<br />
						<br />
						<p:commandButton value="OK" oncomplete="confirmacaoAlteracao.hide();"  />
					</h:panelGroup>
				</h:form>
			</p:dialog>
			
			<p:dialog header="Alteração de senha" widgetVar="editPassword" resizable="false" modal="true" width="400" showEffect="clip" hideEffect="fold">
				
				<h:form prependId="false">
					
					<h:panelGrid columns="2" cellpadding="3" cellspacing="1" id="gridCad">
						
						<h:outputText value="Senha antiga:" styleClass="fmt_label_form_cadastro" />
						<p:password label="Senha antiga" maxlength="6" value="#{marcacaoConsultaPacienteBean.form.senhaAntiga}" required="true" id="oldPassword" feedback="false" size="10">
							<f:validateLength maximum="6" minimum="6" />
						</p:password>
						
						<h:outputText />
						<h:message for="oldPassword" id="msgOldPassword" styleClass="msg_erro_required" />
						
						<h:outputText value="Nova senha:" styleClass="fmt_label_form_cadastro" />
						<p:password maxlength="6" label="Nova senha" value="#{marcacaoConsultaPacienteBean.form.novaSenha}" required="true" id="newPassword" feedback="false" size="10">
							<f:validateLength maximum="6" minimum="6" />
						</p:password>
						
						<h:outputText />
						<h:message for="newPassword" id="msgNewPassword" styleClass="msg_erro_required" />
						
						<h:outputText value="Reptir nova senha:" styleClass="fmt_label_form_cadastro" />
						<p:password maxlength="6" label="Repetir nova senha" value="#{marcacaoConsultaPacienteBean.form.repetirNovaSenha}" required="true" id="repeatNewPassword" feedback="false" size="10">
							<f:validateLength maximum="6" minimum="6" />
						</p:password>
						
						<h:outputText />
						<h:message for="repeatNewPassword" id="msgRepeatNewPassword" styleClass="msg_erro_required" />
						

						<p:commandButton id="btEdit" value="Alterar Senha" action="#{marcacaoConsultaPacienteBean.alterarSenha}" oncomplete="call_modal_password_sucess();" update="msgOldPassword,msgNewPassword,msgRepeatNewPassword,call_func_password_sucess,gridResponseEdit" />
						<p:commandButton value="Cancelar" onclick="editPassword.hide();" />
	
					</h:panelGrid>
				
				</h:form>
				
			</p:dialog>
			
			<p:dialog id="msgModalEditPassword" header="Aviso" widgetVar="confirmacaoAlteracaoPassword" resizable="false" modal="true" width="320" showEffect="clip" hideEffect="fold">
				<h:form prependId="false" id="formModalPassword">
					<h:panelGroup layout="block" style="text-align:center" id="gridResponseEdit">
						<h:outputText styleClass="#{requestScope.password_sucess eq 'sucesso' ? 'sucesso_consulta' : 'erro_consulta'}" value="#{requestScope.password_sucess eq 'sucesso' ? 'Alteração feita com sucesso' : 'Erro, dados inválidos'}" />
						<br />
						<br />
						<p:commandButton value="OK" oncomplete="confirmacaoAlteracaoPassword.hide();editPassword.hide();"  />
					</h:panelGroup>
				</h:form>
			</p:dialog>
			
			<h:panelGroup id="call_func_password_sucess">
				<script type="text/javascript">
					function call_modal_password_sucess(){
						if(#{!empty requestScope.password_sucess}){
							confirmacaoAlteracaoPassword.show();
						}
					}
				</script>
			</h:panelGroup>		
		
	</ui:define>
</ui:composition>